Repository navigation
Navigation: Surface blocks and variations in Link UI search results - #78345
sarthaknagoshe2002 wants to merge 5 commits into
Conversation
…, and correct a11y in link UI
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Did a quick code review. The larger question is if this is the right design direction. I'm going to tag the original issue for discussion. I think the Components team also has some thoughts on the direction for this design.
I think adding allowed blocks to the LinkUI is the right move. They're hard to find otherwise. I'm not sure about the category/taxonomy items though. I think those might be better to surface when searching for the specific taxonomy item rather than including the alternate category block? For example, if I want to add a category, like "Favorites," I would rather type "Favorites" than type "Category" -> Select Category block -> Type "Favorites"
What do you think?
| @@ -97,11 +124,13 @@ function UnforwardedLinkUI( props, ref ) { | |||
| const [ initialSearchValue, setInitialSearchValue ] = useState( '' ); | |||
| // Tracks the live search input between renders without causing re-renders. | |||
| const searchInputValueRef = useRef( '' ); | |||
| const [ searchInputValue, setSearchInputValue ] = useState( '' ); | |||
There was a problem hiding this comment.
Why do we need to add searchInputValue to state instead of relying on the ref?
There was a problem hiding this comment.
We have to use state here because updating a Ref doesn't trigger a re-render. If we only update the ref, the matching items array will never recalculate and the dropdown UI won't visually update as the user types. The state trigers the render cycle needed for real time filtering. Happy to be corrected here & open to a more optimized approach.
|
|
||
| // Filter insertable blocks by both capabilities AND the live search input in one pass. | ||
| // Empty query > no results (avoids flooding the UI before the user types). | ||
| const matchingItems = useMemo( () => { |
There was a problem hiding this comment.
I think this useMemo is trying to recalculate a lot of things on each keystroke. I'd think we should be able to grab what blocks are allowed in one pass on mount and then store that to filter just the matching blocks on query update.
There was a problem hiding this comment.
What would be the preferred architectural approach here? Is there a different pattern you'd recommend here?
|
I ended up going a different direction with how to address this. Added blocks to search results via a new |
What?
Closes #77074 & Closes #76803
This PR enables users to search for and insert allowed inner blocks (such as Site Logo, Search, or Home link) & block variations (like Category Link, Page Link, etc.) directly from the Navigation block's Link UI popover.
It also introduces contextual badges to the dropdown suggestions to help users distinguish between standard links, block variations, and standalone blocks.
Why?
Previously, adding inner blocks or specific entity variations to the Navigation block required a cumbersome, multi-step workflow separated from standard link addition. For example, adding a Home link required knowing to click "Add Block" -> "Browse All" -> Search "Home".
By integrating block and variation search directly into the Link UI's primary search bar, we:
How?
Uses
useSelectto gather all available block types and navigation link variations, and check their insertion permissions. It then filters this list in real-time based on the user's search input and whether the blocks/variation are actually allowed within the Navigation menu. Finally, it passes these matching blocks/variation down into theLinkUIToolscomponent, which loops through the results to display clickable insertion buttons for the user.Introduces a
getVariationBadgeLabelhelper to dynamically generate right-aligned badges (e.g., "Category Link", "Block", "Taxonomy") for the search results, ensuring users know exactly what type of item they are inserting.Testing Instructions
Screenshots or screencast